package com.example.todolist.exception;

import com.example.todolist.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(TodoNotFoundException.class)
    public Result<Void> handleTodoNotFoundException(TodoNotFoundException e) {
        log.error("待办事项未找到: {}", e.getMessage());
        return Result.error(404, e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result<Void> handleException(Exception e) {
        log.error("系统发生意外错误: ", e);
        return Result.error("系统发生意外错误，请稍后重试");
    }
} 